export const bankCardValid=(bankCardNum) =>{
  let res = (bankCardNum + '').match(/[0-9]+/)
  if (!res) return false
  if (res[0].length < 13 && res[0].length > 19) return false
  const lastNum = parseInt(bankCardNum.substr(bankCardNum.length - 1, 1), 10)
  const first15Num = bankCardNum.substr(0, bankCardNum.length - 1)
  const newArr = []
  for (let i = first15Num.length - 1; i > -1; i--) {
    newArr.push(parseInt(first15Num.substr(i, 1), 10))
  }
  const arrJiShu = [] // 奇数位*2的积 >9
  let sumJiShu = 0 // 奇数位*2 < 9 的数组之和
  let sumOuShu = 0 // 偶数位数组之和
  for (let j = 0; j < newArr.length; j += 1) {
    if ((j + 1) % 2 === 1) {
      if (newArr[j] * 2 < 9) {
        sumJiShu += newArr[j] * 2
      } else {
        arrJiShu.push(newArr[j] * 2)
      }
    } else {
      sumOuShu += newArr[j]
    }
  }
  let sumJiShuChild1 = 0 // 奇数位*2 >9 的分割之后的数组个位数之和
  let sumJiShuChild2 = 0 // 奇数位*2 >9 的分割之后的数组十位数之和
  for (let h = 0; h < arrJiShu.length; h++) {
    sumJiShuChild1 += arrJiShu[h] % 10
    sumJiShuChild2 += parseInt(arrJiShu[h] / 10, 10)
  }
  const sumTotal = sumJiShu + sumOuShu + sumJiShuChild1 + sumJiShuChild2
  const k = sumTotal % 10 === 0 ? 10 : sumTotal % 10
  const luhn = 10 - k
  if (lastNum === luhn) {
    return true
  } else {
    return false
  }
}
